﻿@using FactoryManagement.Common
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="~/Xadmin/css/font.css">
    <link rel="stylesheet" href="~/Xadmin/css/xadmin.css">
    <script src="~/Xadmin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="~/Xadmin/js/xadmin.js"></script>
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <div class="layui-collapse">
                            <div class="layui-colla-item">
                                <h2 class="layui-colla-title">配料单信息<i class="layui-icon layui-colla-icon"></i></h2>
                                <div class="layui-colla-content">
                                    <form class="layui-form" action="" id="SaleDetail" lay-filter="SaleDetail">
                                        <div class="layui-form-item">
                                            <div class="layui-inline">
                                                <label class="layui-form-label">配料单名</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="ingredient_name" id="ingredient_name" autocomplete="off" class="layui-input" disabled>
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label">商品名</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="good_name" id="good_name" autocomplete="off" class="layui-input" disabled>
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label">单位</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="unit" id="unit" autocomplete="off" class="layui-input" disabled>
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label">成本</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="sum_money" id="sum_money" autocomplete="off" class="layui-input" disabled>
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label">操作人</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="user_name" id="user_name" autocomplete="off" class="layui-input" disabled>
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label">创建时间</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="createtime" id="createtime" autocomplete="off" class="layui-input" disabled>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <div class="layui-inline">
                                                <label class="layui-form-label">备注</label>
                                                <div class="layui-input-inline">
                                                    <textarea id="L_remarks" name="remarks" class="layui-textarea" disabled=""></textarea>
                                                    <input type="hidden" id="ingredientid" name="ingredientid" />
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-card-body ">
                        <button class="layui-btn" onclick="openAddOne()"><i class="layui-icon"></i>添加商品</button>
                        <table class="layui-hide" id="supplierTable" lay-filter="supplierTable"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/html" id="barContract">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
<script>
    //添加一条原料
    function openAddOne() {
        var ingredientid = $("#ingredientid").val();
        layer.open({
            type: 2,
            title: '添加',
            fixed: false, //不固定
            maxmin: true,
            content: `/Produce/IngredientDetailAddOne`,
            area: ['470px', '400px'],
            success: function(layero, index){
                var iframe = window['layui-layer-iframe'+index];
                //调用子页面的全局函数
                iframe.childChild(ingredientid);
            }
        });
    }
    layui.use(['laydate', 'form', 'table', 'form'],
        function () {
            var table = layui.table;
            var form = layui.form;
            //监听行工具事件
            table.on('tool(supplierTable)',
                function(obj) {
                    var data = obj.data;
                    if (obj.event === 'del') {
                        layer.confirm('真的删除行么',
                            function(index) {
                                $.ajax({
                                    url: `/api/Produce/DeleteIngredientOne?id=${data.listid}`,
                                    type: 'Patch',
                                    success: function (res) {
                                        if (res.code === 0) {
                                            layer.msg(res.msg);
                                            window.location.reload();
                                            layer.close(index);
                                        } else {
                                            layer.msg(res.msg);
                                        }
                                    }
                                });
                            });
                    } else if (obj.event === 'edit') {
                        xadmin.open('编辑', `/Produce/IngredientDetailUpdateOne/${data.listid}`, 470, 400);
                    }
                });
        });
    //父页面调用子页面方法
    function child(data) {
        $("#ingredientid").val(data);
        layui.use(['laydate', 'form', 'table', 'form'],
            function () {
                var form = layui.form;
                var table = layui.table;
                table.render({
                    elem: '#supplierTable'
                    , url: `/api/Produce/GetIngredientDetail?ingredientid=${data}`
                    , limit: 15
                    , limits: [15, 25, 35]
                    , title: '用户数据表'
                    , cols: [[
                        { field: 'raw_name', title: '原料名', fixed: 'left', sort: true}
                        , { field: 'raw_number', title: '数量', sort: true}
                        , { field: 'unit', title: '单位', sort: true }
                        , { fixed: 'right', title: '操作', toolbar: '#barContract' }
                    ]]
                    , page: true
                });
                //得到配料信息
                $.ajax({
                    url: `/api/Produce/GetIngredientTitle?ingredientid=${data}`,
                    type: 'get',
                    data: { page: 1, limit: 1000 },
                    success: function (res) {
                        if (res.code === 0) {
                            form.val('SaleDetail', res.data[0]);
                        }
                    }
                });
            });
    }
</script>
</body>
</html>